package com.sahyadri.web.servlet.handler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;

import com.sahyadri.web.util.security.UserHolder;

/**
 * This {@link HandlerExceptionResolver} implementation just logs the unhandled exception at the ERROR log level 
 * and then delegates to parent class to perform the exception to view resolution.
 * The common {@link SimpleMappingExceptionResolver} class does not log the original exception and so the stack trace
 * often gets swallowed unless the logging level is turned up on the spring DispatcherServlet.
 * 
 * @see HandlerExceptionResolver
 *@see SimpleMappingExceptionResolver
 */
public class SimpleMappingAndLoggingExceptionResolver extends
		SimpleMappingExceptionResolver {

	private final Logger log = Logger.getLogger(this.getClass());

	
	@Autowired
	private UserHolder userHolder;
	
	@Override
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {
		
		// Log exception then allow super class to do it's thing.
		log.error("Unhandled exception filtered up to HandlerExceptionResolver.", ex);
		
		return super.resolveException(request, response, handler, ex);
	}

	
	
}
